<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增设备材料合同出入库单')" />
    <th:block th:include="include :: datetimepicker-css" />
    <style type="text/css">
        table label.error{position: inherit;}select + label.error{z-index:1;right:40px;}
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-sbclhtcrkd-add">
        	<h4 class="form-header h4">基本信息</h4>
        	<input name="gcProjectid" id="gcProjectid" th:value="${gcProjectSbclht.gcProjectid}" type="hidden">
        	<input name="sbclhtId" id="sbclhtId" th:value="${gcProjectSbclht.id}" type="hidden">
        	<input name="type" id="type" th:value="0" type="hidden">
            <div class="form-group">    
                <label class="col-sm-2 control-label is-required">合同编号：</label>
                <div class="col-sm-4">
                    <input name="orderNo" class="form-control" required type="text" autoComplete="off" readonly="readonly" th:value="${gcProjectSbclht.orderNo}">
                </div>
                <label class="col-sm-2 control-label is-required">项目名称：</label>
                <div class="col-sm-4">
                    <input name="xmmc" class="form-control" type="text" autoComplete="off" required th:value="${gcProjectSbclht.name}" readonly="readonly">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">项目地点：</label>
                <div class="col-sm-4">
                    <input name="xmdd" class="form-control" type="text" autoComplete="off" th:value="${xmdz}" >
                </div>
                <label class="col-sm-2 control-label is-required">供货单位：</label>
                <div class="col-sm-4">
                	<input name="ghdw" class="form-control" type="text" autoComplete="off" th:value="${gcProjectSbclht.supplyName}" readonly="readonly"  required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label is-required">日期：</label>
                <div class="col-sm-4">
                    <div class="input-group date">
                        <input name="riq" class="form-control" placeholder="yyyy-MM-dd" type="text" autoComplete="off" required th:value="${#dates.format(riq, 'yyyy-MM-dd')}" >
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <h4 class="form-header h4">人员信息</h4>
            <div class="form-group">
				<label class="col-sm-2 control-label is-required">项目负责人：</label>
                <div class="col-sm-2">
                    <input name="xmfzr" class="form-control" type="text" autoComplete="off" required >
                </div> 
                <label class="col-sm-2 control-label is-required">入库仓管员：</label>
                <div class="col-sm-2">
                    <input name="ckzg" class="form-control" type="text" autoComplete="off" required>
                </div>
                <label class="col-sm-2 control-label is-required">入库会计：</label>
                <div class="col-sm-2">
                    <input name="huij" class="form-control" type="text" autoComplete="off" required >
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label is-required">出库仓管员：</label>
                <div class="col-sm-2">
                    <input name="cksh" class="form-control" type="text" autoComplete="off" required >
                </div>
                <label class="col-sm-2 control-label is-required">出库会计：</label>
                <div class="col-sm-2">
                    <input name="ckhj" class="form-control" type="text" autoComplete="off" required >
                </div>
            </div>
            <h4 class="form-header h4">表单项</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
					    <table id="bootstrap-table"></table>
					</div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:src="@{/js/jquery.tmpl.js}"></script>
    <script th:inline="javascript">
        var prefix = ctx + "gcgl/sbclhtcrkd"
        $("#form-sbclhtcrkd-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-sbclhtcrkd-add').serialize());
            }
        }

        $("input[name='riq']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
	    	// 初始化数据, 可以由后台传过来
		    var options = {
                pagination: false,
		        showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
		        columns: [
		        {
		        	field: 'index',
		        	align: 'center',
		        	title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	var columnId = $.common.sprintf("<input type='hidden' name='item[%s].xuh' value='%s'>", index, row.id);
                    	return columnIndex + $.table.serialNumber(index) + columnId;
                    }
                },
		        {
		            field: 'mingc',
		            align: 'center',
		            title: '名称',
		            width:200,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control mingccount' type='text' autoComplete='off' name='item[%s].mingc' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'guig',
		            align: 'center',
		            title: '规格',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control guigcount' type='text' autoComplete='off' name='item[%s].guig' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'danw',
		            align: 'center',
		            title: '单位',
		            width:80,
		            formatter: function(value, row, index) {
		        		var data = [{ index: index, type: value }];
		                return $("#itemDanw").tmpl(data).html();
                    }
		        },
		        {
		            field: 'shul',
		            align: 'center',
		            title: '数量',
		            width:80,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control shulcount' type='text' autoComplete='off' name='item[%s].shul' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'danj',
		            align: 'center',
		            title: '单价',
		            width:80,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control danjcount' type='text' autoComplete='off' name='item[%s].danj' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'memo',
		            align: 'center',
		            title: '备注',
		            width:200,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control memocount' type='text' autoComplete='off' name='item[%s].memo' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
                    title: '操作',
                    align: 'center',
                    width:80,
                    formatter: function(value, row, index) {
                    	var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
		    };
		    $.table.init(options);
		});
        
        $.validator.addMethod("mingccount", function(value, element) {
            return !this.optional(element);
        }, "名称必填。");
        $.validator.addMethod("guigcount", function(value, element) {
            return !this.optional(element);
        }, "规格必填。");
        $.validator.addMethod("shulcount", function(value, element) {
            return !this.optional(element) && (value <= 100000 && value >= 1);
        }, "数量长度区间1-100000。");
        $.validator.addMethod("danjcount", function(value, element) {
            return !this.optional(element) && (value <= 10000000 && value >= 1);
        }, "单价长度区间1-10000000。");
        
        function submitHandler(index, layero) {
            if ($.validate.form()) {
            	var data = $("#form-sbclhtcrkd-add").serializeArray();
                $.operate.saveTab("/gcgl/sbclhtcrkd/add", data);
            }
        }
        
        function addRow() {
        	var count = $("#" + table.options.id).bootstrapTable('getData').length;
        	var row = {
                index: $.table.serialNumber(count),
                mingc: "",
                guig: "",
                danw: "",
                shul: 0,
                danj: 0,
                memo: "",
            }
        	sub.addRow(row);
        }
    </script>
</body>
</html>

<!-- 单位 -->
<script id="itemDanw" type="text/x-jquery-tmpl">
<div>
<select class='form-control' name='item[${index}].danw'>
	<option value="个" {{if type==="个"}}selected{{/if}}>个</option>
	<option value="件" {{if type==="件"}}selected{{/if}}>件</option>
	<option value="台" {{if type==="台"}}selected{{/if}}>台</option>
	<option value="面" {{if type==="面"}}selected{{/if}}>面</option>
	<option value="米" {{if type==="米"}}selected{{/if}}>米</option>
	<option value="组" {{if type==="组"}}selected{{/if}}>组</option>
	<option value="套" {{if type==="套"}}selected{{/if}}>套</option>
	<option value="吨" {{if type==="吨"}}selected{{/if}}>吨</option>
	<option value="根" {{if type==="根"}}selected{{/if}}>根</option>
	<option value="座" {{if type==="座"}}selected{{/if}}>座</option>
<option value="块" {{if type==="块"}}selected{{/if}}>块</option>
<option value="片" {{if type==="片"}}selected{{/if}}>片</option>
<option value="KG" {{if type==="KG"}}selected{{/if}}>KG</option>
</select>
</div>
</script>